package homework.mission4;

import java.util.Scanner;

public class StudentManageTest {
    public static void main(String[] args) {

        // 创建学生管理系统对象
        StudentManageSystem manage = new StudentManageSystem();

        // 获取用户输入对象
        Scanner sc = new Scanner(System.in);
        String select = null;
        boolean loop = true;

        while (loop) {
            System.out.println("请输入您的选择");
            System.out.println("1: 增加学生信息");
            System.out.println("2: 删除学生信息");
            System.out.println("3: 修改学生信息");
            System.out.println("4: 查找学生信息");
            System.out.println("5: 遍历学生信息");
            System.out.println("e: 推出");

            // 接收用户输入
            select = sc.next();
            switch (select) {
                case "1":
                    // 学号录入
                    System.out.println("请输入您要添加的学生的学号");
                    int id = sc.nextInt();
                    if(id < 0) {
                        System.out.println("学号输入不正确，请重新选择");
                        break;
                    }
                    // 姓名年龄录入
                    System.out.println("请输入姓名");
                    String name = sc.next();
                    System.out.println("请输入年龄");
                    int age = sc.nextInt();

                    // 生成学生对象
                    Student addStudent = new Student(id, name, age);

                    // 添加学生信息
                    manage.add(addStudent);

                    // 打印
                    manage.printStudents();

                    break;
                case "2":
                    System.out.println("请输入要删除学生的学号");

                    int delId = sc.nextInt();
                    manage.del(delId);

                    // 打印
                    manage.printStudents();

                    break;
                case "3":
                    System.out.println("请输入您要修改的学生信息的学号");
                    int changeId = sc.nextInt();

                    // 获取要修改学生在列表中的位置索引
                    int index = manage.getIndex(changeId);
                    if(index == -1) {
                        System.out.println("要修改的学生信息不存在");
                        break;
                    }

                    System.out.println("请输入要修改的学生的姓名");
                    String changeName = sc.next();
                    System.out.println("请输入要修改的学生的年龄");
                    int changeAge = sc.nextInt();

                    Student changeStudent = new Student(changeId, changeName, changeAge);

                    // 修改
                    manage.change(index, changeStudent);

                    // 打印
                    manage.printStudents();

                    break;
                case "4":
                    System.out.println("请输入您要查找的学生的学号");
                    int findId = sc.nextInt();

                    Student findStudent = manage.find(findId);
                    if(findStudent == null) {
                        System.out.println("你要查找的学生不存在");
                    } else {
                        System.out.println(findStudent);
                    }

                    break;
                case "5":
                    // 遍历学生信息
                    manage.printStudents();

                    break;
                case "e":
                    loop = false;
                    break;
                default:
                    System.out.println("请重新选择");
                    break;
            }
        }
    }
}
